package com.mvc4g.example.client.product.views;

import com.google.gwt.user.client.ui.TextBox;
import com.mvc4g.client.Event;
import com.mvc4g.example.client.product.ProductBean;

public class CreateProductView extends AbstractProductView {

	private TextBox name = null;
	private TextBox price = null;

	protected void finishCreation() {
		name = new TextBox();
		price = new TextBox();
		grid.setWidget(0, 1, name);
		grid.setWidget(1, 1, price);
	}

	public void init(ProductBean product) {
		if(product != null){
		name.setText(product.getName());
		price.setText(product.getPrice());
		}
		else{
			name.setText(EMPTY_STRING);
			price.setText(EMPTY_STRING);
		}
	}

	protected String getButtonText() {
		return "Create";
	}

	protected void buttonAction() {
		ProductBean product = new ProductBean();
		product.getName(name.getText());
		product.setPrice(price.getText());
		controller.handleEvent(new Event(CREATE_PRODUCT, product));
	}

}
